package com.lxf.cn.rabbitmq;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * Created by liaoxuefeng on 2018/11/2.
 */
//@Component
public class Consumer {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @RabbitHandler
    @RabbitListener(queues = "${queues.name}")
    public void consumer(Message message) {
        String str = new String(message.getBody());
        if(!str.equals("")&&str!=null){
            if(message.getMessageProperties().getContentType().equals(MessageProperties.CONTENT_TYPE_JSON)){
                System.out.printf("类型为json"+str);
            }else if(message.getMessageProperties().getContentType().equals(MessageProperties.CONTENT_TYPE_TEXT_PLAIN)){
                System.out.printf("类型为str"+str);
            }
        }else {
            logger.info("{null}");
        }

    }

}
